package com.msb.singleton;

/**
 * @Auther： WangLei
 * @Date： 2021/8/2-08-02-22:55
 * @Description: com.msb.singleton.LazyBonesSync1 在方法上添加同步锁
 * @version: 1.0
 */
public class LazyBonesSync1 {
    private LazyBonesSync1(){}

    private static LazyBonesSync1 INSTANCE = null;


    public static  synchronized LazyBonesSync1 getInstance(){
        if(INSTANCE == null){

            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            INSTANCE = new LazyBonesSync1();
        }


        return INSTANCE;
    }

    public static void main(String[] args) {
        for(int i = 0;i < 100 ; i++){
            new Thread(() ->
                System.out.println(LazyBonesSync1.getInstance().hashCode())
            ).start();
        }
    }

}
